<template>
  <div class="container">
    <header>
      <div class="icon" @click="change">
        <img src="../assets/2.png" alt />
        <span>家庭记账</span>
      </div>
      <!-- 账户管理、银行卡管理、统计管理、收入支出数据管理、数据分析、记账提醒、用户信息安全保护 -->
      <div class="route">
        <el-menu :default-active="activeIndex" class="el-menu-demo" mode="horizontal" router>
          <el-menu-item index="index">首页</el-menu-item>
          <el-menu-item index="account">记账</el-menu-item>
          <el-menu-item index="statictical">统计</el-menu-item>
          <el-menu-item index="manage">管理</el-menu-item>
          <el-menu-item index="information" class="infor">
            <i class="el-icon-user-solid"></i>
            <span>{{username}}</span>
          </el-menu-item>
        </el-menu>
      </div>
      <el-button plain class="exit" @click="logout">退出</el-button>
    </header>
    <div class="body">
      <router-view @parfun="revamp"></router-view>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      username: '',
      activeIndex: ''
    };
  },
  created () {
    this.username = window.sessionStorage.getItem("username")
    this.activeIndex = this.$route.path.substring(1, this.$route.path.length)
    // this.activeIndex = 'account'
  },
  methods: {
    revamp(newName) {
      this.username = newName;
    },
    logout(){
      this.$router.push('/login')
      window.sessionStorage.clear()
    },
    change(){
      this.activeIndex = 'account'
    }
  }
};
</script>

<style lang="less" scoped>
.container {
  height: 100%;
  width: 100%;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  align-items: center;

  header {
    height: 10%;
    width: 80%;
    background-color: #ccc;
    display: flex;
    justify-content: space-between;

    .icon {
      margin-left: 15px;
      display: flex;
      align-items: center;
      font-size: 30px;
      font-weight: 600;
      img {
        margin-right: 5px;
        width: 60px;
        height: 60px;
      }
    }
    .route {
      min-width: 40%;
      height: 100%;
      flex: 1;
      ul {
        height: 100%;
        list-style: none;
        display: flex;
        justify-content: space-evenly;
        align-items: center;
      }
      .infor {
        margin-left: 50px;
        align-self: flex-end;
      }
    }
    .exit {
      align-self: center;
      height: 40px;
      width: 70px;
    }
  }

  .body {
    flex: 1;
    height: 100%;
    width: 80%;
    background-color: #fff;
    // background-color: red;
  }
}
</style>